/**
 * 实体权限服务注册中心
 *
 * @export
 * @class AuthServiceRegister
 */
export class AuthServiceRegister{

    /**
     * AuthServiceRegister 单例对象
     *
     * @private
     * @static
     * @memberof AuthServiceRegister
     */
    private static AuthServiceRegister: AuthServiceRegister;

    /**
     * 所有AuthService Map对象
     *
     * @private
     * @static
     * @memberof AuthServiceRegister
     */
    private static allAuthServiceMap: Map<string, any> = new Map();

    /**
     * Creates an instance of AuthServiceRegister.
     * @memberof AuthServiceRegister
     */
    constructor() {
        this.init();
    }

    /**
     * 获取allAuthServiceMap 单例对象
     *
     * @public
     * @static
     * @memberof AuthServiceRegister
     */
    public static getInstance() {
        if (!this.AuthServiceRegister) {
            this.AuthServiceRegister = new AuthServiceRegister();
        }
        return this.AuthServiceRegister;
    }

    /**
     * 初始化
     *
     * @protected
     * @memberof AuthServiceRegister
     */
    protected init(): void {
                AuthServiceRegister.allAuthServiceMap.set('orderdetails', () => import('../authservice/orderdetails/orderdetails-auth-service'));
        AuthServiceRegister.allAuthServiceMap.set('order1', () => import('../authservice/order1/order1-auth-service'));
        AuthServiceRegister.allAuthServiceMap.set('pcmap', () => import('../authservice/pcmap/pcmap-auth-service'));
        AuthServiceRegister.allAuthServiceMap.set('saleplatform', () => import('../authservice/saleplatform/saleplatform-auth-service'));
        AuthServiceRegister.allAuthServiceMap.set('chartentity', () => import('../authservice/chartentity/chartentity-auth-service'));
        AuthServiceRegister.allAuthServiceMap.set('customer', () => import('../authservice/customer/customer-auth-service'));
        AuthServiceRegister.allAuthServiceMap.set('dynamicentity', () => import('../authservice/dynamic-entity/dynamic-entity-auth-service'));
        AuthServiceRegister.allAuthServiceMap.set('majorentity', () => import('../authservice/majorentity/majorentity-auth-service'));
        AuthServiceRegister.allAuthServiceMap.set('orderdetail', () => import('../authservice/orderdetail/orderdetail-auth-service'));
    }

    /**
     * 获取指定AuthService
     *
     * @public
     * @memberof UIServiceRegister
     */
    public async getService(context: any, entityKey: string) {
        const importService = AuthServiceRegister.allAuthServiceMap.get(entityKey);
        if (importService) {
            const importModule = await importService();
            return importModule.default.getInstance(context);
        }
    }

}